package shuffle;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardGame {
    public static final String[] suits = {"♥","♦","♠","♣"};
    /*
    * 生成52张扑克牌
    * */
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j < 13; j++) {
                /*String suit = suits[i];
                Card card = new Card(suit,j);
                cardList.add(card);*/
                cardList.add(new Card(suits[i],j));
            }
        }
        return cardList;
    }
    /*
    * 洗牌
    * */
    public void shuffle(List<Card> cardList) {
        //生成随机数
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0; i--) {
            //生成一个0-i的随机数
            int k = random.nextInt(i);
            //与i下标交换位置
            Card tmp = cardList.get(i);
            cardList.set(i,cardList.get(k));
            cardList.set(k,tmp);
        }
    }
    /*
    * 发牌
    * */
    public List<List<Card>> getCard(List<Card> cardList) {
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            hand1.add(cardList.remove(i));
            hand2.add(cardList.remove(i));
            hand3.add(cardList.remove(i));
        }
        List<List<Card>> list = new ArrayList<>();
        list.add(hand1);
        list.add(hand2);
        list.add(hand3);
        return list;
    }
}
